<%@ page session="true" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
  
   <c:choose> 
  <c:when test='${code == "+OK"}'>  
<img src='images/loading/loading1.gif'  id="deploadimage"/>   
<table border="0" width="100%">	
 <tr>
  <td>
                                           
                                                     
<div id="mamount0" style="border:0; color:#f6931f; font-weight:bold;" />
</div>
<div id="mselector0"></div>
<br>

<div id="mamount1" style="border:0; color:#f6931f; font-weight:bold;" />
</div>
<div id="mselector1"></div>
<br>

<div id="mamount2" style="border:0; color:#f6931f; font-weight:bold;" />
</div>
<div id="mselector2"></div>
<br>

<div id="mamount3" style="border:0; color:#f6931f; font-weight:bold;" />
</div>
<div id="mselector3"></div>
<br>

<div id="mamount4" style="border:0; color:#f6931f; font-weight:bold;" />
</div>
<div id="mselector4"></div>
<br>

<div id="mamount5" style="border:0; color:#f6931f; font-weight:bold;" />
</div>
<div id="mselector5"></div>
<br>
											
                                        </td>
                                    </tr>
									<tr>
                                        <td>
                                            <span class="genbutton" id="addDep">Deploy Army</span>
                                        </td>
                                    </tr>
                                </table>


    
<script language="javascript">
var locid=${dep};

var currentValue =[0,0,0,0,0,0,0,0];
var maxvalue =[0,0,0,0,0,0,0,0,0];

var i;

<c:forEach items="${currentDeployed}" var="cd">
i=parseInt(${cd.key});
currentValue[i]=(<c:out value="${cd.value}"/>);
 </c:forEach>

 <c:forEach items="${freeResources}" var="fr">
 i=parseInt(${fr.key});
 maxvalue[i]=(<c:out value="${fr.value}"/>);
 maxvalue[i]+=currentValue[i];
  </c:forEach>


 
  
$('#addDep').button();

$(function() {
		
		$("#mselector0").slider({
			value:currentValue[0],
			min: 0,
			max: maxvalue[0],
			animate: true,
			slide: function(event, ui) {
				$("#mamount0").html('Army: ' + ui.value + " / Free: " + (maxvalue[0]-ui.value));
			}
		});
		$("#mamount0").html('Army: ' + $("#mselector0").slider("value")+ " / Free: " + (maxvalue[0]-$("#mselector0").slider("value")));

	$("#mselector1").slider({
			value:currentValue[1],
			min: 0,
			max: maxvalue[1],
			animate: true,
			slide: function(event, ui) {
				$("#mamount1").html('Tank: ' + ui.value + " / Free: " + (maxvalue[1]-ui.value));
			}
		});
		$("#mamount1").html('Tank: ' + $("#mselector1").slider("value") + " / Free: " + (maxvalue[1]-$("#mselector1").slider("value")));

	$("#mselector2").slider({
			value:currentValue[2],
			min: 0,
			max: maxvalue[2],
			animate: true,
			slide: function(event, ui) {
				$("#mamount2").html('Aircraft: ' + ui.value + " / Free: " + (maxvalue[2]-ui.value));
			}
		});
		$("#mamount2").html('Aircraft: ' + $("#mselector2").slider("value") + " / Free: " + (maxvalue[2]-$("#mselector2").slider("value")));

	$("#mselector3").slider({
			value:currentValue[3],
			min: 0,
			max: maxvalue[3],
			animate: true,
			slide: function(event, ui) {
				$("#mamount3").html('Navy: ' + ui.value + " / Free: " + (maxvalue[3]-ui.value));
			}
		});
		$("#mamount3").html('Navy: ' + $("#mselector3").slider("value") + " / Free: " + (maxvalue[3]-$("#mselector3").slider("value")));

	$("#mselector4").slider({
			value:currentValue[4],
			min: 0,
			max: maxvalue[4],
			animate: true,
			slide: function(event, ui) {
				$("#mamount4").html('Spies: ' + ui.value + " / Free: " + (maxvalue[4]-ui.value));
			}
		});
		$("#mamount4").html('Spies: ' + $("#mselector4").slider("value")+ " / Free: " + (maxvalue[4]-$("#mselector4").slider("value")));

	$("#mselector5").slider({
			value:currentValue[5],
			min: 0,
			max: maxvalue[5],
			animate: true,
			slide: function(event, ui) {
				$("#mamount5").html('Submarines: ' + ui.value + " / Free: " + (maxvalue[5]-ui.value));
			}
		});
		$("#mamount5").html('Submarines: ' + $("#mselector5").slider("value") + " / Free: " + (maxvalue[5]-$("#mselector5").slider("value")));


	});


$('#addDep').bind('click', function(event) {

	$.getJSON("adddeployment/add", {
		locID:locid,
	    m0 : $("#mselector0").slider("value"),
	    m1 : $("#mselector1").slider("value"),
	    m2 : $("#mselector2").slider("value"),
	    m3 : $("#mselector3").slider("value"),
	    m4 : $("#mselector4").slider("value"),
	    m5 : $("#mselector5").slider("value")

	}, function(rtnmsg) {
		//FIXME check for invalid returns
		if (null == rtnmsg) {
           noKonnect();
            return;
          }
        if(rtnmsg["status"]=="+OK")
        {
        	 jAlert("Army has been deployed to this location","Army Deployed")
        }
        else  if(rtnmsg["code"]=="EDE")
        {
        	jAlert("Enemy has conquered this territory! Your deployment has been rejected","Location conquered!")
        }
        else
        {
        	jAlert("Unable to deploy army!" + rtnmsg["code"],"Could not deploy")
        }

	    });

});
syncMilServer();
//remove the loading image...
$("#deploadimage").hide();
</script>
  


 </c:when> 
 <c:otherwise>  
 
Enemy combatant has stolen this location from you! You have lost this territory.
Think fast. Act faster!
<script language="javascript">
delayShow();
syncMilServer();
</script>
 </c:otherwise> 
 </c:choose> 
        